home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Arashi 1.1.1 / source code / For your think c folder / VA Kit ƒ / VARandom.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-09  |  1.4 KB  |  85 lines  |  [TEXT/KAHL]

  1. /*/
  2.      Project Arashi: VARandom.c
  3.      Major release: Version 1.1d2, 9/5/95
  4.  
  5.      Last modification: Wednesday, September 9, 1992, 21:42
  6.      Created: Tuesday, April 23, 1991, 0:16
  7.  
  8.      Copyright © 1991-1992, Juri Munkki
  9. /*/
  10.  
  11. #include "VA.h"
  12.  
  13. #ifdef    PURE_C_VERSION_OF_RANDOM
  14. #define    RANDCONST    ((unsigned long)(0x41A7))
  15. #define    HIGH(x)        ((unsigned int)(x>>16))
  16. #define    LOW(x)        ((unsigned int)x)
  17.  
  18. int        VARandom()
  19. {
  20.     register    unsigned    long    temp;
  21.     
  22.     temp = RANDCONST * HIGH(VARandSeed) + HIGH(RANDCONST * LOW(VARandSeed));
  23.     VARandSeed = ((temp & 0x7fff) << 16) + HIGH(temp << 1) + LOW(RANDCONST * VARandSeed);
  24.     
  25.     return    LOW(VARandSeed);
  26. }
  27. #endif
  28.  
  29. int        VARandom()
  30. {
  31. asm    {
  32.         move.w    #0x41A7,D0
  33.         move.w    D0,D2
  34.         mulu.w    2+VARandSeed,D0
  35.         move.l    D0,D1
  36.         clr.w    D1
  37.         swap.w    D1
  38.         mulu.w    VARandSeed,D2
  39.         add.l    D1,D2
  40.         move.l    D2,D1
  41.         add.l    D1,D1
  42.         clr.w    D1
  43.         swap.w    D1
  44.         and.l    #0x0000ffff,D0
  45.         sub.l    #0x7fffFFFF,D0
  46.         and.l    #0x00007fff,D2
  47.         swap.w    D2
  48.         add.l    D1,D2
  49.         add.l    D2,D0
  50.         bpl.s    @positive
  51.         add.l    #0x7fffFFFF,D0
  52. @positive
  53.         move.l    D0,VARandSeed
  54.     }
  55. }
  56.  
  57. int        FastRandom()
  58. {
  59. asm    {
  60.         move.w    #0x41A7,D0
  61.         move.w    D0,D2
  62.         mulu.w    2+randSeed,D0
  63.         move.l    D0,D1
  64.         clr.w    D1
  65.         swap.w    D1
  66.         mulu.w    randSeed,D2
  67.         add.l    D1,D2
  68.         move.l    D2,D1
  69.         add.l    D1,D1
  70.         clr.w    D1
  71.         swap.w    D1
  72.         and.l    #0x0000ffff,D0
  73.         sub.l    #0x7fffFFFF,D0
  74.         and.l    #0x00007fff,D2
  75.         swap.w    D2
  76.         add.l    D1,D2
  77.         add.l    D2,D0
  78.         bpl.s    @positive
  79.         add.l    #0x7fffFFFF,D0
  80. @positive
  81.         move.l    D0,randSeed
  82.     }
  83. }
  84.  
  85.